package SortCode;

/**
 * Created by kechelle on 2020/8/12 16:10
 * 快速排序
 */
public class code1 {

    public static void QuickSort(int[] nums,int left,int right){
        if (left<right){
            int i = left;
            int j = right;
            int key = nums[left];
            while (i<j){
                while (i<j && nums[j]>key) j--;
                while (i<j && nums[i]<key) i++;
                //找到比key大的或小的，交互位置
                if (i<j){
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
            //基数回归中间
            nums[i] = key;
            QuickSort(nums,left,i-1);
            QuickSort(nums,i+1,right);
        }
    }

    public static void main(String[] args) {
        int[] nums = {72,6,57,88,60,42,83,73,48,85};
        QuickSort(nums,0,nums.length - 1);
        for (int num:nums){
            System.out.print(num + " ");
        }
    }
}
